package com.yc;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.stereotype.Component;

@Component
public class MyBeanFactoryPost implements BeanFactoryPostProcessor {
    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory config) throws BeansException {
        // 动态注册 bean 定义
        DefaultListableBeanFactory config1 = (DefaultListableBeanFactory) config;
        BeanDefinition definition = new RootBeanDefinition();
        definition.setBeanClassName("com.yc.spring.bbs.bean.Page");
        definition.setPrimary(true);
        definition.setScope("prototype");
        config1.registerBeanDefinition("myPage",definition);
    }
}
